package com.cwz.swagger.config;

import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: w-demo
 * @description: swagger 配置文件配置
 * @author: Wen
 **/
@Data
@NoArgsConstructor
@Component
@ConfigurationProperties("swagger")
public class SwaggerProperties {
	/**
	 * 是否开启 swagger
	 */
	private Boolean enabled;

	/**
	 * swagger 会解析的包路径
	 **/
	private String basePackage = "";

	/**
	 * swagger 会解析的 url 规则
	 **/
	private List<String> basePath = new ArrayList<>();

	/**
	 * 在 basePath 基础上需要排除的 url 规则
	 **/
	private List<String> excludePath = new ArrayList<>();

	/**
	 * 标题
	 **/
	private String title = "";

	/**
	 * 描述
	 **/
	private String description = "";

	/**
	 * 版本
	 **/
	private String version = "";

	/**
	 * 许可证
	 **/
	private String license = "";

	/**
	 * 许可证 URL
	 **/
	private String licenseUrl = "";

	/**
	 * 服务条款 URL
	 **/
	private String termsOfServiceUrl = "";

	/**
	 * host 信息
	 **/
	private String host = "";

	/**
	 * 联系人信息
	 */
	private Contact contact = new Contact();

	/**
	 * 全局统一鉴权配置
	 **/
	private Authorization authorization = new Authorization();

	@Data
	@NoArgsConstructor
	public static class Contact {
		/**
		 * 联系人
		 **/
		private String name = "";
		/**
		 * 联系人url
		 **/
		private String url = "";
		/**
		 * 联系人email
		 **/
		private String email = "";
	}

	@Data
	@NoArgsConstructor
	public static class Authorization {
		/**
		 * 鉴权策略 ID，需要和 SecurityReferences ID 保持一致
		 */
		private String name = "";

		/**
		 * 需要开启鉴权 URL 的正则
		 */
		private String authRegex = "^.*$";

		/**
		 * 鉴权作用域列表
		 */
		private List<AuthorizationScope> authorizationScopeList = new ArrayList<>();

		/**
		 * token 列表
		 */
		private List<String> tokenUrlList = new ArrayList<>();
	}

	@Data
	@NoArgsConstructor
	public static class AuthorizationScope {
		/**
		 * 作用域名称
		 */
		private String scope = "";

		/**
		 * 作用域描述
		 */
		private String description = "";
	}
}
